//
//  UIBarButtonItem+Extensions.swift
//  Swift微博练习
//
//  Created by 练锦波 on 2016/11/3.
//  Copyright © 2016年 练锦波. All rights reserved.
//

import UIKit

extension UIBarButtonItem{
    
    /// 创建 UIBarButtonitem
    ///
    /// - parameter title:    title
    /// - parameter fontSize: fontSize 默认 16 号
    /// - parameter target:   target
    /// - parameter action:   action
    /// - parameter isBack:   是否是返回按钮 如果是 就加上箭头
    ///
    /// - returns: UIBarButtonItem
    convenience init(title: String, fontSize: CGFloat = 16, target: AnyObject?, action: Selector ,isBack:Bool = false){
        let btn: UIButton = UIButton.cz_textButton(title, fontSize: fontSize, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange)
        btn.addTarget(target, action: action, for: .touchUpInside)
        
        if isBack {
            let imageName = "navigationbar_back_withtext"
            btn.setImage(UIImage(named:imageName), for: UIControlState(rawValue:0))
            btn.setImage(UIImage(named:imageName + "_highlighted"), for: .highlighted)
            btn.sizeToFit()
        }
        
        // self.init 实例化 UIBarButtonItem
        self.init(customView: btn)
    }

}
